<template>
	<view class="after-sales-type">
		<view class="row-1">
			<image :src="realmName + pageData.goodsPic" mode="aspectFill" class="image"></image>
			<view class="text">{{pageData.goodsName}}</view>
		</view>

		<view class="row-2">
			<view class="header">
				<view class="title">申请原因</view>
				<view style="display: flex;align-items: center;" @click="handleSelectr">
					<text style="margin-right: 12rpx;">{{refuseReason?refuseReason:'请选择'}}</text>
					<u-icon name="arrow-right" color="#cccccc" size="18"></u-icon>
				</view>
			</view>
			<view class="content">
				<u--textarea v-model="value1" placeholder="请描述申请售后服务的具体原因"></u--textarea>
			</view>
			<!-- <view class="select-box">
				<view class="tools" v-for="(item,index) in listImage" :key="index">
					<image :src="item" mode="aspectFill" class="image"></image>
					<view class="close" @click="handleClose(index)">
						<u-icon name="close-circle" color="red" size="20"></u-icon>
					</view>
				</view>

				<view class="tools" @click="handleUpImage" v-if="listImage.length<4">
					<view class="icon"></view>
					<view class="text">添加图片/视频（最多4张）</view>
				</view>
			</view> -->
		</view>

		<view class="row-3">
			<view class="btn" @click="handleSubmit">提交</view>
		</view>

		<reason-for-refund @submit="handleCancel" ref="reason-for-refund" title="售后"></reason-for-refund>
	</view>
</template>
<script>
	import reasonForRefund from "../components/reason-for-refund.vue";
	import {
		realmName
	} from "@/http";
	import {
		afterSaleMyOrder,
	} from "@/culturalCreativity/http/my.js";
	export default {
		components: {
			reasonForRefund,
		},
		data() {
			return {
				value1: "",
				realmName,
				listImage: [],
				refuseReason: "",
				afterSalesType: null,
				pageData: {}
			}
		},
		onLoad({afterSalesType}) {
			let title = '';
			this.afterSalesType = afterSalesType;
			switch (Number(afterSalesType)){
				case 1:
					title = '退货原因'
					break;
				case 2:
					title = '退款原因'
					break;
				case 3:
					title = '换货原因'
					break;
				default:
					break;
			};
			uni.setNavigationBarTitle({
				title
			});
			
			this.pageData = uni.getStorageSync('PAGE_DATA');
			console.log("this.pageData", this.pageData);
		},
		methods: {
			handleClose(index) {
				this.listImage = [...this.listImage.slice(0, index), ...this.listImage.slice(index + 1, this.listImage
					.length)];
			},
			handleSelectr() {
				this.$refs['reason-for-refund'].init({});
			},
			handleCancel({
				refuseReason
			}) {
				this.refuseReason = refuseReason;
			},
			handleUpImage() {
				uni.chooseImage({
					sourceType: ["album", "camera"],
					count: 4 - this.listImage.length,
					success: res => {
						// console.log('查看图片:',res.tempFilePaths[0])
						this.listImage.push(res.tempFilePaths[0])
					}
				})
			},
			async handleSubmit() { //提交内容
				uni.showLoading({
					title:"加载中...",
					mask:true
				});
				let form = {
					afterSalesType:this.afterSalesType,
					orderGoodsNumber: this.pageData.orderGoodsNumber ,
					refuseReason: this.refuseReason + ' ' + this.value1
				};
				let res = await afterSaleMyOrder(form);
				uni.hideLoading()
				uni.redirectTo({
					url:"/culturalCreativity/common/afterSalesDetails"
				});
				console.log("退货申请已经提交成功",form);
			}
		}
	}
</script>
<style lang="scss" scoped>
	.after-sales-type {
		.row-3 .btn {
			width: 686rpx;
			height: 80rpx;
			background: #FD8F19;
			border-radius: 40rpx;
			color: #FFFFFF;
			font-size: 32rpx;
			text-align: center;
			line-height: 80rpx;
			margin: 0 auto;
			margin-top: 300rpx;
		}

		.row-2 {
			margin-top: 24rpx;
			width: 100%;
			background: #FFFFFF;
			border-radius: 30rpx;
			box-sizing: border-box;
			padding: 0 32rpx;
			padding-bottom: 8rpx;
			.select-box {
				display: flex;
				align-items: center;
				padding-bottom: 24rpx;

				.tools {
					width: 160rpx;
					height: 160rpx;
					background: #FFFFFF;
					border-radius: 8rpx;
					border: 1rpx solid #BDBDBD;
					display: flex;
					align-items: center;
					justify-content: center;
					flex-direction: column;
					position: relative;

					&+.tools {
						margin-left: 8rpx;
					}

					.close {
						position: absolute;
						right: 4rpx;
						top: 4rpx;
						border-radius: 50%;
						background-color: #FFFFFF;
					}

					.image {
						width: 160rpx;
						height: 160rpx;
					}

					.text {
						color: #C1C1C1;
						font-size: 20rpx;
						width: 130rpx;
						text-align: center;
					}

					.icon {
						margin-bottom: 8rpx;
						width: 48rpx;
						height: 48rpx;
						background: url() center/cover no-repeat;
					}
				}
			}

			.header {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 24rpx 0;
				border-bottom: 1px solid #EEEEEE;
				color: #1F1F1F;
				font-size: 24rpx;

				.title {
					color: #878787;
				}
			}

			.content {
				margin: 24rpx 0;
			}
		}

		.row-1 {
			width: 100%;
			box-sizing: border-box;
			padding: 0 32rpx;
			height: 200rpx;
			background: #FFFFFF;
			border-radius: 0rpx 0rpx 30rpx 30rpx;
			display: flex;
			align-items: center;

			.image {
				width: 120rpx;
				height: 120rpx;
				border-radius: 16rpx;
				margin-right: 24rpx;
			}

			.text {
				width: 542rpx;
				font-size: 24rpx;
				font-weight: 400;
				color: #1F1F1F;
			}
		}

		&::after {
			content: "";
			position: fixed;
			top: 0;
			right: 0;
			bottom: 0;
			left: 0;
			z-index: -1;
			background-color: #F7F7F7;
		}
	}
</style>
